<% layout('/layouts/default.html', {title: '文件归还', libs: ['dataGrid']}){ %>
<script src="${ctxStatic}/common/qr_send_msg.js"></script>



<a href="#" class="btn btn-default" onclick="startTest()" id="openc" style="margin-top: 10px;margin-left: 48%;margin-bottom: 10px">调试</a>
<div style="width: 480px; height: 515px;border: solid 1px black; margin: auto;">

    <div id="qrcode" style="padding: 12px;  background-size: cover;"></div>
    <div id="infor" style="text-align: center;width: 480px;height:35px;overflow: hidden;text-overflow: ellipsis;"></div>
    <div id="con" style="text-align: center;color: red"></div>
</div>

<%}%>

<script src="${ctxStatic}/common/des.js?${_version}"></script>
<script type="text/javascript">
    var tim;
window.onload=function(){

    /*var nr = DesUtils.encode( "dasdassdfasfsdfsd41894184848464561fasfdsajdiasiodjioasji", secretKey);
    new QRCode(document.getElementById("qrcode"), {
        text:nr,
        width: 450,
        height: 450,
        correctLevel: 3
    })
    document.getElementById("infor").innerHTML = "调试二维码"
    document.getElementById("con").innerHTML = "备注:调试完毕点击上方(开启)按钮"*/
    getMess();
    document.getElementById("con").innerHTML = "";
    tim= setInterval(function () {
        getMess()
    },1000*10);

}
  function startTest() {
     clearInterval(tim);
     document.getElementById("openc").innerHTML="开启"
      $("#openc").attr("onclick","startSendMsg()")
      document.getElementById("qrcode").innerHTML=""
      var nr = DesUtils.encode( "dasdassdfasfsdfsd41894184848464561fasfdsajdiasiodjioasji", secretKey);
      new QRCode(document.getElementById("qrcode"), {
          text:nr,
          width: 450,
          height: 450,
          correctLevel: 3
      })
      document.getElementById("infor").innerHTML = "调试二维码"
  }
     function startSendMsg() {
     js.layer.confirm("是否开启",function () {
         document.getElementById("openc").innerHTML="已经开启"
         getMess();
         document.getElementById("con").innerHTML = "";
         setInterval(function () {
             getMess()
         },1000*10);
     })




    }
    var secretKey = '${@Global.getConfig("shiro.loginSubmit.secretKey")}';
    function getMess(){
        $.ajax({
            type: "POST",
            url: "${ctx}/sd/docRecv/getMessageCode",
            contentType: false,
            processData: false,
            success: function (data) {
               console.log("data="+data)

                if (data.result == Global.TRUE) {
                    document.getElementById("qrcode").innerHTML="";
                    document.getElementById("infor").innerHTML = ""

                  var jso=   JSON.stringify(data)
                    console.log(jso)

                    var nr = DesUtils.encode(jso, secretKey);
                    new QRCode(document.getElementById("qrcode"), {
                        text:nr,
                        width: 450,
                        height: 450,
                        correctLevel: 3
                    })
                    document.getElementById("infor").innerHTML = data.data.msgContent
                    console.log("1111111111111")
                }else {
                    //console.log("2222222222222")
                    document.getElementById("qrcode").innerHTML="";
                    document.getElementById("infor").innerHTML = "暂无未发送短信"
                }
            }
        })

    }
</script>
